var NS = NS || {};
NS.Category = NS.Category || {};
NS.Category.Main = (function ($, pageCtrlUtil) {

    var args = {
        pageId: null
    }

    var selectors = {
        div_grid: {id: "grid", jqObj: null},
        input_name: {id: "name", jqObj: null},
        input_type: {id: "type", jqObj: null},
        input_search: {id: "search", jqObj: null},

    }

    var interfaces = {
        getVideoListUrl: $.contextPath + "/category/getGrid",
    }

    var jsonPosts = {}

    var events = {
        executeQuery: function () {
            executeQuery()
        },
    }

    function init(pageId) {
        args.pageId = pageId
        pageCtrlUtil.initSelectors(args.pageId, selectors);
        initEvents();
        initGrid();
    }

    function initEvents() {
      selectors.input_search.jqObj.click(events.executeQuery)
    }

    function initGrid() {
        selectors.div_grid.jqObj.datagrid({
            width: 'auto',
            height: window.innerHeight*0.9-20,
            singleSelect: true,
            autoRowHeight: true,
            striped: true,
            pagination: true,
            loadMsg: "数据加载中....",
            columns: [[
                {field: 'id', hidden: true},
                {field: 'name', title: '分类名称', align:'center',width: 180},
                {field: 'type', title: '分类等级',  align:'center',width: 100},
                {field: 'superName', title: '所属上级分类',  align:'center',width: 150},
            ]],
        })

        executeQuery()
    }

    function executeQuery() {
        var formData = {};
        var name = selectors.input_name.jqObj.value;
        var type = selectors.input_type.jqObj.value;
        formData.name = name;
        formData.type = type;

        selectors.div_grid.jqObj.datagrid({url: interfaces.getVideoListUrl, queryParams: formData})
    };

    return {
        init: init
    }

})(jQuery, NS.PageCtrl.Utils);